package renguanyu.app.auth4fx.service.user;

import renguanyu.app.auth4fx.dao.user.UserRoleDao;
import renguanyu.app.auth4fx.model.user.UserRoleDto;

import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

public class UserRoleService {

    public static List<Map<String, Object>> queryUnownedRoleList(UserRoleDto userRoleDto){
        String userId = userRoleDto.getUserId();
        List<Map<String, Object>> unownedRoleList = UserRoleDao.queryUnownedRoleList(userId);
        return  unownedRoleList;
    }

    public static List<Map<String, Object>> queryOwnedRoleList(UserRoleDto userRoleDto){
        String userId = userRoleDto.getUserId();
        List<Map<String, Object>> ownedRoleList = UserRoleDao.queryOwnedRoleList(userId);
        return ownedRoleList;
    }

    public static int[] saveUserRoleList(Integer size, String userId, List<String> roleId){
        return UserRoleDao.saveUserRoleList(size,userId,roleId);
    }

    public static int deleteUserRoleList(UserRoleDto userRoleDto) {
        List<String> ids = userRoleDto.getIds();
        String inSql = ids.stream().map(id -> "?").collect(Collectors.joining(","));
        return UserRoleDao.deleteUserRoleList(ids,inSql);
    }
}
